package com.pt25.service.sys.interfaces.assembler;

import com.pt25.base.util.JsonUtil;
import com.pt25.service.sys.domain.admin.ddo.AdminPermission;
import com.pt25.service.sys.domain.admin.ddo.AdminRole;
import com.pt25.service.sys.domain.admin.ddo.AdminUser;
import com.pt25.service.sys.interfaces.vo.admin.*;
import com.pt25.service.sys.interfaces.vo.admin.permission.AdminPermissionAddVo;
import com.pt25.service.sys.interfaces.vo.admin.permission.AdminPermissionUpdateVo;
import com.pt25.service.sys.interfaces.vo.admin.role.AdminRoleAddVo;
import com.pt25.service.sys.interfaces.vo.admin.role.AdminRolePageVo;
import com.pt25.service.sys.interfaces.vo.admin.role.AdminRoleUpdateVo;
import com.pt25.service.sys.interfaces.vo.admin.user.AdminUserAddVo;
import com.pt25.service.sys.interfaces.vo.admin.user.AdminUserPageVo;
import com.pt25.service.sys.interfaces.vo.admin.user.AdminUserUpdateVo;


public interface AdminAssembler {

    static AdminUser adminLoginVO2AdminUser(AdminLoginVo adminLoginVO) {
        return AdminUser.builder()
                .admin(adminLoginVO.getUsername())
                .password(adminLoginVO.getPassword())
                .build();
    }

    static AdminUser adminUserAddVO2AdminUser(AdminUserAddVo adminUserAddVO) {
        return AdminUser.builder()
                .admin(adminUserAddVO.getAdmin())
                .password(adminUserAddVO.getPassword())
                .roleIds(adminUserAddVO.getRoleIds())
                .build();
    }

    static AdminUser adminUserUpdateVO2AdminUser(AdminUserUpdateVo adminUserUpdateVO) {
        return AdminUser.builder()
                .id(adminUserUpdateVO.getId())
                .admin(adminUserUpdateVO.getAdmin())
                .password(adminUserUpdateVO.getPassword())
                .roleIds(adminUserUpdateVO.getRoleIds())
                .build();
    }

    static AdminRole adminRoleAddVO2AdminRole(AdminRoleAddVo adminRoleAddVO) {
        return AdminRole.builder()
                .role(adminRoleAddVO.getRole())
                .permissionIds(adminRoleAddVO.getPermissionIds())
                .build();
    }

    static AdminRole adminRoleUpdateVO2AdminRole(AdminRoleUpdateVo adminRoleUpdateVO) {
        return AdminRole.builder()
                .id(adminRoleUpdateVO.getId())
                .role(adminRoleUpdateVO.getRole())
                .permissionIds(adminRoleUpdateVO.getPermissionIds())
                .build();
    }

    static AdminPermission adminPermissionAddVO2AdminPermission(AdminPermissionAddVo adminPermissionAddVO) {
        return AdminPermission.builder()
                .parentId(adminPermissionAddVO.getParentId())
                .permission(adminPermissionAddVO.getPermission())
                .title(adminPermissionAddVO.getTitle())
                .sort(adminPermissionAddVO.getSort())
                .level(adminPermissionAddVO.getLevel())
                .build();
    }

    static AdminPermission adminPermissionUpdateVO2AdminPermission(AdminPermissionUpdateVo adminPermissionUpdateVO) {
        return AdminPermission.builder()
                .id(adminPermissionUpdateVO.getId())
                .parentId(adminPermissionUpdateVO.getParentId())
                .permission(adminPermissionUpdateVO.getPermission())
                .title(adminPermissionUpdateVO.getTitle())
                .sort(adminPermissionUpdateVO.getSort())
                .level(adminPermissionUpdateVO.getLevel())
                .build();
    }

    static AdminRole adminRolePageVOToAdminRole(AdminRolePageVo adminRolePageVO) {
        return JsonUtil.toBean(JsonUtil.toJson(adminRolePageVO), AdminRole.class);
    }

    static AdminUser adminUserPageVOToAdminUser(AdminUserPageVo adminUserPageVO) {
        return JsonUtil.toBean(JsonUtil.toJson(adminUserPageVO), AdminUser.class);
    }
}
